package basics;

import org.junit.Test;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @author: zhenzhong.wang@honeywell.com
 * @date: 2019/8/22 3:13 PM
 */
public class MapTest {

  @Test
  public void test1() {
    Comparator comparator = (a, b) -> {
      if (a.hashCode() > b.hashCode()) {
        return -1; // 返回-1不用调换位置
      } else {
        return 1;  // 返回1需要调换位置
      }
    };
    TreeMap<Object, Object> map = new TreeMap<>(comparator);
    map.put("2", "2");
    map.put("3", "3");
    map.put("1", "1");


    map.forEach((key, value) -> {
      System.out.println(value + "  " + key.hashCode());
    });
  }
}
